<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <meta charset="utf-8" />
    <title>Bone</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <%@ include file="/common/css.jsp"%>
    <!-- END GLOBAL MANDATORY STYLES -->
    <link href="${ctx}/resource/css/promo.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/resource/css/animate.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="${ctx}/resource/js/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/resource/js/jquery-1.10.1.min.js"></script>
	<script type="text/javascript" src="${ctx}/resource/js/jquery-migrate-1.2.1.min.js"></script>
	<script type="text/javascript" src="${ctx}/resource/js/task.js"></script>
	<style type="text/css">
	*{margin: 0px;padding: 0px;font-size: 16px;}
	form{class: form-horizontal}

	/*动态列表样式*/
	.optionList{list-style: none;margin: 0 0 10px 0px;}
	.optionList li{display: block;height: 30px;line-height: 30px;margin-bottom: 20px;}
	.optionList li span, .optionList li input[type='text'], .optionList input[type='button']{display: inline-block;float:left;text-align: left;}
	.optionList li span{}
	.optionList li input[type='text']{}
	.optionList li input[type='button']{}
</style>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed page-full-width">
<!-- BEGIN HEADER -->
<%@ include file="/common/header.jsp"%>
<!-- END HEADER -->

<!--content start-->
<div class="tab-pane row-fluid profile-account" id="tab_1_3" style="margin-top:40px">

    <div class="row-fluid">
        <div class="span2"></div>
        <div class="span8">
            <h3 class="page-title">
                新建投票
            </h3>
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home"></i>
                    <a href="${ctx}/vote/index.do">首页</a>
                    <i class="icon-angle-right"></i>
                </li>
                <li><a href="#">新建投票</a></li>
            </ul>
        </div>
        </div>
        <div class="row-fluid">
        <div class="span2"></div>
        <div class="span8" >
            <!-- BEGIN SAMPLE FORM PORTLET-->
            <div class="portlet box blue">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-reorder"></i>新建投票</div>
                    <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                        <a href="javascript:;" class="remove"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <!-- BEGIN FORM-->
                    <form id="voteForm" action="" class="form-horizontal" enctype="multipart/form-data" onsubmit="return false;">
                        <div class="control-group">
                            <label class="control-label">投票宣传图片</label>
                            <div class="controls">
                                <div class="fileupload fileupload-new" data-provides="fileupload"><input type="hidden" value="" name="">
                                    <div class="input-append">
                                        <div class="span4 uneditable-input" style="width: 420px;">
                                            <i class="icon-file fileupload-exists"></i>
                                            <span class="fileupload-preview"></span>
                                        </div>
													<span class="btn btn-file">
													<span class="fileupload-new">Browse</span>
													<span class="fileupload-exists">更换</span>
													<input type="file" class="default" name="advert" value="">
													</span>
                                        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">删除</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">投票标题</label>
                            <div class="controls">
                                <input type="text" class="span6 m-wrap" name="title" id="title" value="${topic.title}"/>
                                <span class="help-inline"></span>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">投票类型</label>
                            <c:if test="${topic.type == '0'}">
                            <div class="controls">
                                <label class="radio">
                                    <input type="radio" name="type" value="0" checked/>
                                    单选
                                </label>
                                <label class="radio">
                                    <input type="radio" name="type" value="1" />
                                    多选
                                </label>

                            </div>
                            </c:if>
                            <c:if test="${topic.type == '1'}">
                            <div class="controls">
                                <label class="radio">
                                    <input type="radio" name="type" value="0" />
                                    单选
                                </label>
                                <label class="radio">
                                    <input type="radio" name="type" value="1" checked/>
                                    多选
                                </label>
                            </div>
                            </c:if>
                        </div>

                        <div class="control-group">
                            <label class="control-label">投票隐私</label>
                            <c:if test="${topic.scope == '0'}">
                            <div class="controls">
                                <label class="radio">
                                    <input type="radio" name="scope" value="0" checked/>
                                    任何人可投票
                                </label>
                                <label class="radio">
                                    <input type="radio" name="scope" value="1"  />
                                    会员可投票
                                </label>
                            </div>
                            </c:if>
                             <c:if test="${topic.scope == '1'}">
                            <div class="controls">
                                <label class="radio">
                                    <input type="radio" name="scope" value="0" />
                                    任何人可投票
                                </label>
                                <label class="radio">
                                    <input type="radio" name="scope" value="1" checked />
                                    会员可投票
                                </label>
                            </div>
                            </c:if>
                        </div>

                        <div class="control-group">
                            <label class="control-label">投票截止时间</label>
                            <div class="controls">
                                <input name="endTime"  type="text" class="Wdate" value="${createVoteDto.endTime}"
               	onfocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true,minDate:'%y-%M-%d',firstDayOfWeek:1})">
                                <span class="help-inline"></span>
                            </div>
                        </div>
                        <div class="control-group" >
                            <label class="control-label">投票选项</label>
                            <div class="controls" >
                            	<ul class="optionList"></ul>
                                <input type="button" value="添加选项" class="addOption btn green"/>
                            </div>
                        </div>
                        <div class="form-actions">
                            <input type="button" id = "commit" class="btn blue" value="确定"/>
                            <button type="reset" class="btn">重置</button>
                        </div>
                        <input type="hidden" id = "count" name="count" value="${count}"/>
                        <input type="hidden" id = "compareName" name="compareName" value="${topic.title}"/>
                    </form>
                    <!-- END FORM-->
                </div>
            </div>
            <!-- END SAMPLE FORM PORTLET-->


        </div>
    </div>
</div>
<!--end tab-pane-->

<!-- BEGIN FOOTER1 -->
<%@ include file="/common/footer.jsp"%>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS -->
<!-- BEGIN CORE PLUGINS -->
<%@ include file="/common/js.jsp"%>
<!-- END CORE PLUGINS -->
    <script type="text/javascript" src="${ctx}/resource/js/jquery.validate.min.js"></script>
	<script src="${ctx}/resource/js/app.js"></script>
<script>
    jQuery(document).ready(function() {
        App.init();
        jQuery('#promo_carousel').carousel({
            interval: 10000,
            pause: 'hover'
        });
    });

    var i=2;
    $(document).ready(
    function(){  
      $("#add1").click(function(){
    	  i=i+1;
    	  if (i<11){
    	       $("<div id='"+i+"'><div class='controls' ><div><span class='btn red'>"+ i +"</span><input type='text' class='span5 m-wrap' name='content"+ i +"' /><input type='button' value='删除' class='btn yellow delet2'/></div><br></div><div>").clone(true).appendTo("#two")
    	  }

    	  });
    	 $(".delet2").live("click",function(){
    		  $(this).parent().remove();
    		 });
    });
    $(function(){
    	jQuery("#title").blur(function(){
    		jQuery.ajax({
    			type: "post",
    			url:"${ctx}/vote/checkUpdateTitle.do",
    			data:jQuery("#voteForm").serialize(),
    			dataType:"json",
    			success:function(data){
    				if(data.flag=="failure"){
    						layer.msg(data.message);
    					}
    				},
    			error:function(){
    			}
    			});
    		});
    	});
    $(document).ready(
   		 function(){
    		jQuery("#commit").click(function(){
    			jQuery.ajax({
    				type: "post",
    				url:'${ctx}/vote/updateVote.do?tid=' + '${topic.tid}',
    				data:jQuery("#voteForm").serialize(),
    				dataType:"json",
    				success:function(data){
    					if(data.flag=="success"){
    						//提示层
    						layer.msg(data.message);
        					window.location.href="${ctx}/vote/index.do"
    					}else{
    						layer.msg(data.message);
    					}
    				},
					error:function(data){
						alert(JSON.stringify(data));
					}
    			});
    		});
    });

    $(document).ready(function(){
    	init();
    	$(".addOption").click(function(){
    		if(options.length >= 10){
    			return;
    		}
    		var optionIndex = options.length + 1;
    		var option = new OptionEntity(optionIndex);
    		$(".optionList").append(option.option_li);
    	});
    });
    function init(){
    	for(var i=0;i<"${count}";i++){
    		var option = new OptionEntity(i+1);
    		$(".optionList").append(option.option_li);
    	}
    	$(".optionList").find("input[class='span5 m-wrap']").each(function(i){
    		if(i==0){
	    		$(this).val("${createVoteDto.content1}");
    		}else if(i==1){
	    		$(this).val("${createVoteDto.content2}");
    		}else if(i==2){
	    		$(this).val("${createVoteDto.content3}");
    		}else if(i==3){
	    		$(this).val("${createVoteDto.content4}");
    		}else if(i==4){
	    		$(this).val("${createVoteDto.content5}");
    		}else if(i==5){
	    		$(this).val("${createVoteDto.content6}");
    		}else if(i==6){
	    		$(this).val("${createVoteDto.content7}");
    		}else if(i==7){
	    		$(this).val("${createVoteDto.content8}");
    		}else if(i==8){
	    		$(this).val("${createVoteDto.content9}");
    		}else if(i==9){
	    		$(this).val("${createVoteDto.content10}");
    		}
    	});
    }
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>